<?php

class Ialbum_Widget_AlbumNavigationController extends Engine_Content_Widget_Abstract
{
  public function indexAction()
  {
	if (!Engine_Api::_()->core()->hasSubject()) {
      return $this->setNoRender();
    }
    $this->view->subject = $subject = Engine_Api::_()->core()->getSubject();
    if(!($subject instanceof Album_Model_Album))
  	{
      return $this->setNoRender();
    }
    $viewer = Engine_Api::_()->user()->getViewer();
      // Do other stuff
    $this->view->mine = true;
    $this->view->canEdit = Engine_Api::_()->core()->getSubject()->authorization()->isAllowed($viewer, 'edit');
    if( !$subject->getOwner()->isSelf(Engine_Api::_()->user()->getViewer()) ) {
      $subject->getTable()->update(array(
        'view_count' => new Zend_Db_Expr('view_count + 1'),
      ), array(
        'album_id = ?' => $subject->getIdentity(),
      ));
      $this->view->mine = false;
    }
    $this->view->canComment = $canComment =  Engine_Api::_()->core()->getSubject()->authorization()->isAllowed($viewer, 'comment'); 
    $front_controller = Zend_Controller_Front::getInstance ();
	$this->view->view_type = $front_controller->getRequest()->getParam('view_type', '');
  }
}
